// 必填校验
export const required = (message) => {
  return {
    required: true,
    message: message,
    trigger: 'blur'
  }
}

// 手机号校验
export const phone = (message = '请输入正确的手机号') => {
  return {
    pattern: /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/,
    message: message,
    trigger: 'blur'
  }
}

// 纯整数校验
export const integer = {
  pattern: /^(\-|\+)?\d+?$/,
  message: '请输入正确的数字',
  trigger: 'blur'
}

// 纯整数或小数校验
export const float = {
  pattern: /^(\-|\+)?\d+(\.\d+)?$/,
  message: '请输入正确的数字（整数或小数）',
  trigger: 'blur'
}

// 日期校验
export const date = {
  type: 'date',
  message: '请选择日期',
  trigger: 'blur'
}

// 校验字符长度
export function len(min = 0, max = 255, msg = `字符长度应在 ${min} 到 ${max} 个字符之间`) {
  return {
    min,
    max,
    message: msg,
    trigger: 'blur'
  }
}

// 是否小写字母校验
export const letterCheck = (message = '请输入小写字母') => {
  return {
    pattern: /^([a-z\u4e00-\u9fa5\d]*?)$/,
    message: message,
    trigger: 'blur'
  }
}

export default {
  len: len,
  required: required,
  phone: phone,
  integer: integer,
  float: float,
  date: date,
  letterCheck: letterCheck
}
